/*
 * @Author: chunlai
 * @Date: 2023-12-07 08:51:58
 * @LastEditTime: 2025-11-19 09:47:29
 * @LastEditors: minsheng_insurance_agency_zhoucl
 * @FilePath: \01.latest-short-insure\src\translate\risks\rules.js
 * @Description:
 */

import { userAge } from "@/methods/globals.js";
import { Toast } from "vant";
export const validRules = (list, data, rootState) => {
  // console.log("validRules---0", list);
  let insertParams = rootState.insert;
  let applicant = insertParams.applicant;
  const bbrArr = insertParams.bbrList,
    bbrNum = bbrArr.length,
    bbr0Item = bbrArr[0];

  // console.log('validRules', type)
  let state = [];
  let mainRisk = list.find((todo) => todo.ismain),
    mainAmnt = mainRisk.amnt,
    mainPrem = Number(mainRisk.prem),
    // risksInfo = getMessage("risksInfo"), // 险种配置原始数据
    insuAge = userAge(bbr0Item.birthDate),
    insuSex = bbr0Item.sex,
    insuRela = `${bbr0Item.relationToAppnt || "4"}`,
    appntOccu = applicant.occupationClass,
    insuOccu = bbr0Item.occupationClass,
    insuOccuName = bbr0Item.occupationCodeName,
    insuSheBao = bbr0Item.socialInsuFlag,
    appntAge = applicant.birthDate
      ? userAge(applicant.birthDate)
      : applicant.age;
  // 多被保人年龄取最大值
  if (bbrNum > 1) {
    insuAge = Math.max(...bbrArr.map((e) => userAge(e?.birthDate)));
  }
  /* ======= 已选信息赋值 =======*/
  state = list.map((item, index) => {
    /* ===== 字段修改/赋值 ===== */
    if (item.varietyCode == data.varietyCode) {
      item[data.type] = data.val;
      if (data.valTypeKey) {
        item[data.valTypeKey] = data.valType;
      }
    }

    /* ===== 选项设置/过滤 ===== */
    /* === 投保份数 === */
    // 0.缴费年期校验份数最大值 -payYearCheckMultMax

    // 1.计算保费-new
    if (item.multCountPrem) {
      item.prem = item.mult * item.countBaseMoney;
    }
    // 2.计算保额-new
    if (item.multCountAmnt) {
      item.amnt = item.mult * item.countBaseMoney;
    }
    // 3.份数选择 -new
    if (item.multArr && item.multArr.length > 0) {
      item.multList = item.multArr.filter((multNum) => {
        let flag = true;
        if (multNum.maxAge && multNum.maxAge < insuAge) {
          flag = false;
        }
        return flag;
      });
      let multTag = item.multList.find((cell) => cell.value == item.mult);
      if (!multTag) {
        multTag = item.multList[0] || {};
        item.mult = multTag.value;
      }
    }
    // 4.泰康
    if (item.amntPremSet) {
      if (item.amntPremSet == "amntArr") {
        // 续保险种规则匹配
        let renewalFlag = rootState.instype || "0",
          cfgArr = [];
        if (renewalFlag == "2") {
          cfgArr = item.renewalConfigs;
        } else {
          cfgArr = item.firstInsureConfigs;
        }
        const filterObj = cfgArr.filter((item) => {
          return insuAge >= item.minAge && insuAge <= item.maxAge;
        })[0];
        item.programmeName = filterObj.insurType || "";
        // 泰康职业4类保额降低
        let caseArr = insuOccu == "4" ? filterObj.cases_2 : filterObj.cases;
        item.amntArr = caseArr;
      }
    }
    /* === 保障期限 --- ok === */
    // 1.列表过滤/赋值
    if (item.insureYearArr && item.insureYearArr.length > 0) {
      item.insureYearList = item.insureYearArr.filter((insYear) => {
        let flag = true;
        if (insYear.maxAge && insYear.maxAge < insuAge) {
          flag = false;
        }
        return flag;
      });
      let insuTag = item.insureYearList.find(
        (cell) => cell.value == item.insuYear
      );
      if (!insuTag) {
        insuTag = item.insureYearList[0];
        item.insuYear = insuTag.value;
      }
      if (insuTag.type) {
        item.insuYearType = insuTag.type;
      }
      if (insuTag.setPullAge) {
        item.pullAge = insuTag.setPullAge;
      }
      // 如果保障期限下配置有缴费年期 即使用
      if (insuTag.payendyearArr) {
        item.payendyearList = insuTag.payendyearArr;
      }
    }
    // 2.保险期间规则
    if (item.insurYearRela) {
      if (item.insurYearRela == "mainInsurSame") {
        // 保险期间=主险保险期间
        item.insuYear = mainRisk.insuYear;
        item.insuYearType = mainRisk.insuYearType;
      } else if (item.insurYearRela == "mainPayendSame") {
        // 保险期间=主险交费期间
        if (mainRisk.payendyear !== "趸交") {
          item.insuYear = mainRisk.payendyear;
          item.insuYearType = mainRisk.payendyearType;
        }
      }
    }

    /* === 缴费年期 --- ok === */
    // 1.列表过滤/赋值
    if (item.payendyearArr && item.payendyearArr.length > 0) {
      item.payendyearList = item.payendyearArr.filter((payYear) => {
        let flag = true;
        if (payYear.maxAge && payYear.maxAge < insuAge) {
          flag = false;
        }
        return flag;
      });
      let payEdnTag = item.payendyearList.find(
        (cell) => cell.value == item.payendyear
      );
      if (!payEdnTag) {
        payEdnTag = item.payendyearList[0] || {};
        item.payendyear = payEdnTag.value;
      }
      if (payEdnTag.type) {
        item.payendyearType = payEdnTag.type;
      }
      // 如果缴费年期下配置有保障期限  即使用
      if (payEdnTag.insureYearArr) {
        item.insureYearArr = payEdnTag.insureYearArr;
      }
    }
    // 2.附加险缴费年期取主险赋值
    if (item.payendYearRela !== undefined) {
      const payendYearRelaMs = item.payendYearRela;
      if (payendYearRelaMs === "mainSlice" && mainRisk.payendyear !== "趸交") {
        item.payendyear = mainRisk.payendyear - 1; //交费期间=主险交费期间-1;
      } else if (item.payendYearRela == "mainSame") {
        item.payendyear = mainRisk.payendyear;
        // 待确定
        if (item.payendyearList) {
          let tagyear = item.payendyearList.find(
            (years) => years.value == item.payendyear
          );
          if (!tagyear) {
            item.errorTip = "当前主险缴费年期无法匹配该附加险";
            item.canChoose = true;
            item.checked = false;
            item.preChecked = true;
          } else {
            item.preChecked = false;
          }
        }
      }
      item.payendyearType = mainRisk.payendyearType;
    }

    /* === 保额选择 -new === */
    if (item.amntArr && item.amntArr.length > 0) {
      item.amntList = item.amntArr.filter((amnI) => {
        let flag = true;
        if (amnI.maxAge && amnI.maxAge < insuAge) {
          flag = false;
        }
        if (amnI.minAge && amnI.minAge > insuAge) {
          flag = false;
        }
        return flag;
      });
      let f1obj = item.amntList.find((ele4) => ele4.value == item.amnt);
      if (!f1obj) {
        f1obj = item.amntList[0];
      }
      item.amnt = `${f1obj.value}`;
      if (f1obj.prem) {
        item.prem = f1obj.prem;
      }
      if (f1obj.insurInfo) {
        item.dutyAmntPremTable = f1obj.insurInfo;
      }
    }
    /* === 险种计划类 === */
    let planDescLabel = "";
    // 1.计划所属大类(为了给plans赋值,该参数值不参与保费的试算)-new
    if (item.planBiggerArr && item.planBiggerArr.length > 0) {
      item.planBiggerList = item.planBiggerArr;
      // .filter((planI) => {
      //   let flag = true;
      //   return flag;
      // });
      let planBiggerTag = item.planBiggerList.find(
        (cell) => cell.value == item.planBig
      );
      if (!planBiggerTag) {
        planBiggerTag = item.planBiggerList[0];
        item.planBig = planBiggerTag.value;
      }
      planDescLabel = `${planBiggerTag.label}-`;
      /*初始化 + 点击大类按钮 >>> 赋值*/
      if (item.plansArr.length === 0 || data.type === "planBig") {
        // 1-1.计划大类所属的 小类
        if (planBiggerTag.plansArr) {
          item.plansArr = planBiggerTag.plansArr;
        }
        // 1-2.计划大类所属的 责任
        if (planBiggerTag.dutyArr) {
          item.dutyList = planBiggerTag.dutyArr;
        }
        if (planBiggerTag.zympeList) {
          item.zympeList = planBiggerTag.zympeList;
        }
        // 责任多选按钮
        if (planBiggerTag.addiDutyArr) {
          item.addiDutyList = planBiggerTag.addiDutyArr;
        }
      }
    }
    // 2.计划选择(含编码)-new
    if (item.plansArr && item.plansArr.length > 0) {
      item.plansList = item.plansArr.filter((planI) => {
        let flag = true;
        if (planI.maxAge && planI.maxAge < insuAge) {
          flag = false;
        }
        // INIT_PLANSS中初始化过滤迁至此处
        if (planI.hasSocial && planI.hasSocial !== insuSheBao) {
          flag = false;
        }
        return flag;
      });
      let planTag = item.plansList.find((cell) => cell.value == item.planCode);
      if (!planTag) {
        planTag = item.plansList[0];
        item.planCode = planTag.value;
      }
      planDescLabel += `${planTag.label}`;
      if (planTag.content) {
        item.planDescCont = `${planTag.content}`;
      }
      // 2-1.计划对应的保障责任列表
      if (planTag.guarantees) {
        item.guaranteesList = planTag.guarantees;
      }
      // 2-2.产品计划固定保额/保费(华安、平安、众惠)
      if (planTag.fixAmnt) {
        item.amnt = planTag.fixAmnt;
        item.amntType = "text";
      }
      if (planTag.fixPrem) {
        item.prem = planTag.fixPrem;
        item.premType = "text";
      }
      if (planTag.fixInsuYear) {
        item.insuYear = planTag.fixInsuYear;
      }
      if (planTag.fixInsuYearType) {
        item.insuYearType = planTag.fixInsuYearType;
      }
    }
    if (planDescLabel) {
      item.planDescLabel = planDescLabel;
    }
    // 3.计划关联的住院免赔额(含编码)-new
    if (item.zympeList && item.zympeList.length > 0) {
      let planTag = item.zympeList.find((cell) => cell.value == item.zympeCode);
      if (!planTag) {
        planTag = item.zympeList[0];
        item.zympeCode = planTag.value;
      }
    }
    /* ======= rules规则外,初步校验(主险使用较多) ======= */
    const rulesList = item.rules || [],
      findPrem = rulesList.find((fnd) => fnd.type === "premLimit"),
      findAnmt = rulesList.find((fnd) => fnd.type === "amntLimit");
    // 1.保费校验类-new
    if (findPrem && findPrem.check_payendyear === "1") {
      const targetList = item.payendyearArr,
        findObj4 = targetList.find((fnd) => fnd.value === item.payendyear);
      if (findObj4) {
        if (findObj4.minPrem) {
          findPrem.minPrem = findObj4.minPrem;
          if (Number(item.prem) < findObj4.minPrem) {
            Toast(
              `${item.productName}，交费期间选择${findObj4.label}，最低保费为${findObj4.minPrem}元`
            );
            item.prem = findObj4.minPrem;
          }
        } else if (findObj4.maxPrem) {
          findPrem.maxPrem = findObj4.maxPrem;
          if (Number(item.prem) > findObj4.maxPrem) {
            // 最高保费校验
            Toast(
              `${item.productName}，交费期间选择${findObj4.label}，最高保费为${findObj4.maxPrem}元`
            );
            item.prem = findObj4.maxPrem;
          }
        }
      }
    }

    // 2.保额校验类-new
    if (findAnmt && findAnmt.check_payendyear === "1") {
      const targetList = item.payendyearArr,
        findObj5 = targetList.find((fnd) => fnd.value === item.payendyear);
      if (findObj5) {
        if (findObj5.minAmnt) {
          findAnmt.minAmnt = findObj5.minAmnt;
          if (Number(item.amnt) < findObj5.minAmnt) {
            Toast(
              `${item.productName}，交费期间选择${findObj5.label}，最低保额为${findObj5.minAmnt}元`
            );
            item.amnt = findObj5.minAmnt;
          }
        } else if (findObj5.maxAmnt) {
          findAnmt.maxAmnt = findObj5.maxAmnt;
          if (Number(item.amnt) > findObj5.maxAmnt) {
            Toast(
              `${item.productName}，交费期间选择${findObj5.label}，最高保额为${findObj5.maxAmnt}元`
            );
            item.amnt = findObj5.maxAmnt;
          }
        }
      }
    }
    return item;
  });
  /* ======= 已选险种信息rules校验 =======*/
  state = state.map((item, index, arr) => {
    /* === rules公共校验规则 === */
    if (item.rules && item.rules.length > 0) {
      const ruleLen = item.rules.length;
      if (!item.preChecked) {
        item.errorTip = "";
        item.canChoose = false;
      }
      for (let i = 0; i < ruleLen; i++) {
        let ele = item.rules[i];
        if (item.ismain || item.checked) {
          if (ele.type == "amntLimit") {
            // 保额校验限制
            if (ele.maxAmnt && Number(item.amnt) > ele.maxAmnt) {
              item.amnt = ele.maxAmnt;
              Toast(`${item.productName}，最高保额${ele.maxAmnt}元`);
              break;
            } else if (ele.minAmnt && Number(item.amnt) < ele.minAmnt) {
              item.amnt = ele.minAmnt;
              Toast(`${item.productName}，最低保额${ele.minAmnt}元`);
              break;
            } else if (
              ele.checkBaseMoney &&
              Number(item.amnt) % ele.checkBaseMoney !== 0
            ) {
              item.amnt = ele.minAmnt || ele.maxAmnt;
              Toast(
                `${item.productName}，保额需为 ${ele.checkBaseMoney} 元的整数倍`
              );
              break;
            } else if (
              ele.ageCheckAmnt !== undefined &&
              ele.ageCheckAmnt.length > 0
            ) {
              const ageObj = ele.ageCheckAmnt.find(
                (it3) => insuAge > it3.minAge && insuAge <= it3.maxAge
              );

              if (ageObj) {
                if (
                  ageObj.minAmnt !== undefined &&
                  Number(item.amnt) < ageObj.minAmnt
                ) {
                  Toast(
                    `${ageObj.minAge}-${ageObj.maxAge}周岁，投保本险种最低基本保险金额为${ageObj.minAmnt}元`
                  );
                  item.amnt = ageObj.minAmnt;
                  break;
                } else if (
                  ageObj.maxAmnt !== undefined &&
                  Number(item.amnt) > ageObj.maxAmnt
                ) {
                  Toast(
                    `${ageObj.minAge}-${ageObj.maxAge}周岁，投保本险种最高基本保险金额为${ageObj.maxAmnt}元`
                  );
                  item.amnt = ageObj.maxAmnt;
                  break;
                } else if (
                  ageObj.baseLevel &&
                  Number(item.amnt) % ageObj.baseLevel != 0
                ) {
                  Toast(`基本保险金额须为${ageObj.baseLevel}元整数倍`);
                  item.amnt = ageObj.minAmnt || ageObj.maxAmnt;
                  break;
                }
              }
            } else if (
              ele.occuLimitAmnt !== undefined &&
              ele.occuLimitAmnt.length > 0
            ) {
              const checkList4 = ele.occuLimitAmnt,
                len4 = checkList4.length;
              for (let i = 0; i < len4; i++) {
                const item4 = checkList4[i];
                if (
                  insuOccuName === item4.code &&
                  Number(item.amnt) > item4.value
                ) {
                  item.amnt = item4.value + "";
                  Toast(
                    `被保人所选职业为特殊职业，所选保额不得大于${
                      item4.value / 10000
                    }万，请重新选择保额`
                  );
                  break;
                }
              }
            } else if (ele.mainAmntMulMax !== undefined) {
              if (Number(item.amnt) > mainAmnt * ele.mainAmntMulMax) {
                item.amnt = mainAmnt * ele.mainAmntMulMax;
                Toast(
                  `${item.productName}，最高保额不超过主险保额的${ele.mainAmntMulMax}倍`
                );
                break;
              }
            } else if (ele.amntRateToOtherRisk !== undefined) {
              /*与target险种保额的投保比例值*/
              let checkObj1 = {};
              if (Array.isArray(ele.amntRateToOtherRisk)) {
                checkObj1 = ele.amntRateToOtherRisk.find((ele) => {
                  let flag = false;
                  arr.forEach((li) => {
                    if (ele.target.includes(li.varietyCode)) {
                      flag = true;
                    }
                  });
                  return flag;
                });
              } else {
                checkObj1 = ele.amntRateToOtherRisk;
              }
              const targetArr = Array.isArray(checkObj1.target)
                  ? checkObj1.target
                  : [checkObj1.target],
                findItem1 = arr.find(
                  (insu) =>
                    targetArr.includes(insu.varietyCode) &&
                    (insu.checked || insu.ismain)
                );
              if (findItem1) {
                if (checkObj1.maxRate !== undefined) {
                  const maxRateVal = (findItem1.amnt - 0) * checkObj1.maxRate;
                  if (maxRateVal < Number(item.amnt)) {
                    item.amnt = ele.minAmnt || ele.maxAmnt;
                    let resValue = `${checkObj1.maxRate}倍`;
                    if (checkObj1.maxRate < 1) {
                      resValue = `${checkObj1.maxRate * 100}%`;
                    }
                    Toast(
                      `${item.productName}，最高保额不能超过 ${findItem1.productName} 保额的 ${resValue} `
                    );
                  }
                } else if (checkObj1.minRate !== undefined) {
                  const minRateVal = (findItem1.amnt - 0) * checkObj1.minRate;
                  if (minRateVal > item.amnt - 0) {
                    item.amnt = ele.minAmnt || ele.maxAmnt;
                    let resValue = `${checkObj1.maxRate}倍`;
                    if (checkObj1.maxRate < 1) {
                      resValue = `${checkObj1.maxRate * 100}%`;
                    }
                    Toast(
                      `${item.productName}，最低保额不能低于 ${findItem1.productName} 保额的 ${resValue}`
                    );
                  }
                }
              }
            } else if (ele.premRateToOtherRisk !== undefined) {
              /*与target险种保费的投保比例值*/
              const checkObj2 = ele.premRateToOtherRisk,
                targetArr2 = Array.isArray(checkObj2.target)
                  ? checkObj2.target
                  : [checkObj2.target],
                findItem1 = arr.find(
                  (insu) =>
                    targetArr2.includes(insu.varietyCode) &&
                    (insu.checked || insu.ismain)
                );
              if (findItem1) {
                const tgPrem = Number(findItem1.prem),
                  tgPayYear = Number(
                    findItem1.payendyear !== "趸交" ? findItem1.payendyear : "1"
                  );
                if (checkObj2.maxRate !== undefined) {
                  const tgTotalPrem = tgPrem * tgPayYear * checkObj2.maxRate;
                  if (Number(item.amnt) > tgTotalPrem) {
                    item.amnt = ele.minAmnt || ele.maxAmnt;
                    Toast(
                      `${item.productName}，保额不能超过主险总保费的${
                        checkObj2.maxRate * 100
                      }%`
                    );
                  }
                }
              }
            }
          } else if (ele.type == "premLimit") {
            const maxBasePrem = ele.maxPrem || 100000000;
            // 保费校验限制
            if (Number(item.prem) > maxBasePrem) {
              item.prem = maxBasePrem;
              Toast(`${item.productName}，最高保费${maxBasePrem}元`);
              break;
            }
            if (ele.minPrem && Number(item.prem) < ele.minPrem) {
              item.prem = ele.minPrem;
              Toast(`${item.productName}，最低保费${ele.minPrem}元`);
              break;
            } else if (
              ele.checkBaseMoney &&
              Number(item.prem) % ele.checkBaseMoney !== 0
            ) {
              item.prem = ele.minPrem || ele.maxPrem;
              Toast(
                `${item.productName}，保费需为 ${ele.checkBaseMoney} 元的整数倍`
              );
              break;
            }
          } else if (ele.type == "payYearLimit") {
            // 缴费年期校验
            if (ele.sameMainPay && ele.sameMainPay.length > 0) {
              if (ele.sameMainPay.includes(mainRisk.payendyear)) {
                if (item.payendyear != mainRisk.payendyear) {
                  Toast(ele.errTips);
                }
                item.payendyear = mainRisk.payendyear;
              }
            } else if (ele.mainPayend && ele.mainPayend.length > 0) {
              if (!ele.mainPayend.includes(mainRisk.payendyear)) {
                item.errorTip = ele.errTips;
              }
            }
          } else if (ele.type == "multLimit") {
            // 投保份数校验
            // 如果被保人是成年人，则当前订单累计总保费（首年保费*交费年期）*20%计入风险保额
            // 如果是未成年人，不校验
            if (insuAge >= 18 && ele.occuLimitMult !== undefined) {
              const checkList5 = ele.occuLimitMult || [],
                len5 = checkList5.length;
              if (len5 > 0) {
                let totalFee1 =
                  Number(item.prem) *
                  Number(item.payendyear === "趸交" ? "1" : item.payendyear) *
                  0.2;
                for (let i = 0; i < len5; i++) {
                  const item5 = checkList5[i];
                  if (
                    insuOccuName === item5.code &&
                    Number(totalFee1) > item5.value
                  ) {
                    item.mult = item.multMin + "";
                    Toast(
                      `被保人所选职业为特殊职业，所选保额不得大于${
                        item5.value / 10000
                      }万，请重新选择保额`
                    );
                    break;
                  }
                }
              }
            }
          }
        }
        /* === 选择前校验险种是否可选 === */
        // else {
        if (ele.type == "premLimit") {
          if (ele.mainPremLimit !== undefined) {
            const limitObj = ele.mainPremLimit;
            if (
              limitObj.minPrem !== undefined &&
              Number(mainRisk.prem) < limitObj.minPrem
            ) {
              item.errorTip = `主险保费最低${limitObj.minPrem}元,才可附加本险种`;
              item.canChoose = true;
              item.checked = false;
              break;
            } else if (
              limitObj.maxPrem !== undefined &&
              Number(mainRisk.prem) > limitObj.maxPrem
            ) {
              item.errorTip = `主险保费最高${limitObj.maxPrem}元,才可附加本险种`;
              item.canChoose = true;
              item.checked = false;
              break;
            }
          }
        }
        // 年龄校验
        else if (ele.type == "ageLimit") {
          if (ele.tbrMaxAge && appntAge > ele.tbrMaxAge) {
            item.errorTip =
              ele.errTips || `投保人最大年龄不超过：${ele.tbrMaxAge}周岁`;
            item.limitedBy = "tbr";
            item.canChoose = true;
            item.checked = false;
            break;
          } else if (ele.tbrMinAge && appntAge < ele.tbrMinAge) {
            item.errorTip =
              ele.errTips || `投保人最小年龄不低于：${ele.tbrMinAge}周岁`;
            item.limitedBy = "tbr";
            item.canChoose = true;
            item.checked = false;
            break;
          } else if (ele.maxAge && insuAge > ele.maxAge) {
            item.errorTip =
              ele.errTips || `被保险人最大年龄不超过：${ele.maxAge}周岁`;
            item.limitedBy = "bbr";
            item.canChoose = true;
            item.checked = false;
            break;
          } else if (ele.minAge && insuAge < ele.minAge) {
            item.errorTip =
              ele.errTips || `被保险人最小年龄不低于：${ele.minAge}周岁`;
            item.limitedBy = "bbr";
            item.canChoose = true;
            item.checked = false;
            break;
          } else if (
            ele.tbrAgeCheckMainPayYear &&
            ele.tbrAgeCheckMainPayYear.length > 0
          ) {
            // 豁免险:投保人年龄>>缴费期间 (爱心+利安/415008)
            const findObj6 = ele.tbrAgeCheckMainPayYear.find(
              (fnd) => appntAge >= fnd.minValue && appntAge <= fnd.maxValue
            );
            if (findObj6 && findObj6.payyear.includes(mainRisk.payendyear)) {
              item.errorTip = `投保人年龄${findObj6.minValue}-${findObj6.maxValue}岁,且主险缴费期间为${mainRisk.payendyear}年交时,不可选`;
              item.limitedBy = "tbr";
              item.canChoose = true;
              item.checked = false;
              break;
            }
          }
        } else if (ele.type == "relationLimit") {
          // 投保关系校验
          if (ele.excludeSelf !== undefined && insuRela == ele.excludeSelf) {
            item.errorTip = ele.errTips;
            item.limitedBy = "bbr";
            item.canChoose = true;
            item.checked = false;
            break;
          }
        } else if (ele.type == "socialSecurityLimit") {
          // 社保限制校验
          if (ele.value !== insuSheBao) {
            item.errorTip = ele.errTips;
            item.limitedBy = "bbr";
            item.canChoose = true;
            item.checked = false;
            break;
          }
        } else if (ele.type == "occupationLimit") {
          // 职业限制校验
          let zhiyeLevel = insuOccu,
            uname = "被保险人";
          if (ele.tagrgetUser && ele.tagrgetUser == "tbr") {
            zhiyeLevel = appntOccu;
            uname = "投保人";
          }
          if (
            ele.maxLevel !== undefined &&
            Number(zhiyeLevel) >= Number(ele.maxLevel)
          ) {
            item.errorTip =
              ele.errTips ||
              `${uname}${ele.maxLevel}级（含）以上职业不得投保本险`;
            item.limitedBy = "bbr";
            item.canChoose = true;
            item.checked = false;
            break;
          } else if (ele.disLevelArr) {
            if (ele.disLevelArr.includes(zhiyeLevel)) {
              item.errorTip =
                ele.errTips || `${uname}${zhiyeLevel}级职业不得投保`;
              item.limitedBy = "bbr";
              item.canChoose = true;
              item.checked = false;
              break;
            }
          } else if (
            ele.levelCheckAmnt !== undefined &&
            ele.levelCheckAmnt.length > 0
          ) {
            const checkList2 = ele.levelCheckAmnt,
              len2 = checkList2.length;
            let errFlag = false;
            for (let i = 0; i < len2; i++) {
              const item2 = checkList2[i];
              if (
                Number(zhiyeLevel) == item2.level &&
                Number(item.amnt) > item2.maxAmnt
              ) {
                errFlag = true;
                item.errorTip = `职业等级 ${item2.level} 级最高 ${item2.maxAmnt} 万`;
                item.limitedBy = "bbr";
                item.canChoose = true;
                item.checked = false;
                break;
              }
            }
            if (errFlag) {
              break;
            }
          }
        } else if (ele.type == "sexLimit") {
          // 性别限制校验
          if (ele.value !== insuSex) {
            item.errorTip = `该险种仅限${
              ele.value === "1" ? "女士" : "男士"
            }可投保,请确认修改`;
            item.limitedBy = "bbr";
            item.canChoose = true;
            item.checked = false;
            break;
          }
        }
      }
    }
    return item;
  });

  return state;
};
